package com.jrx.anytxn.transaction.controller.api;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.transaction.dto.loan.MatchingAmortMethodReq;
import com.jrx.anytxn.transaction.dto.loan.MatchingAmortMethodRes;
import com.jrx.anytxn.transaction.dto.loanRelationInfo.*;
import com.jrx.anytxn.transaction.handler.ILoanRelationInfoHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 贷款相关信息查询
 * 利率、要素等
 *
 * @author : zhenghaopu
 * 2019/11/21
 */
@Api(tags = "贷款相关接口")
@RestController
@RequestMapping(value = "/api/transaction/loanRelationInfo")
public class LoanRelationInfoController {

    private static final Logger logger = LoggerFactory.getLogger(LoanRelationInfoController.class);

    @Autowired
    private ILoanRelationInfoHandler loanRelationInfoHandler;

    @ApiOperation(value = "贷款要素查询", notes = "贷款要素查询")
    @PostMapping(value = "/queryLoanElement")
    public TxnRespResult<LoanElementQueryRes> queryLoanElement(@Valid @RequestBody LoanElementQueryReq loanElementQueryReq) throws Exception {
        TxnRespResult<LoanElementQueryRes> result = new TxnRespResult<>();
        result.getSuccess(loanRelationInfoHandler.queryLoanElement(loanElementQueryReq));
        return  result;
    }

    @ApiOperation(value = "贷款利率查询", notes = "贷款利率查询")
    @PostMapping(value = "/queryLoanRate")
    public TxnRespResult<LoanRateQueryRes> queryLoanElement(@Valid @RequestBody LoanRateQueryReq loanRateQueryReq) throws TxnException {
        TxnRespResult<LoanRateQueryRes> result = new TxnRespResult<>();
        result.getSuccess(loanRelationInfoHandler.queryLoanRate(loanRateQueryReq));
        return  result;
    }

    @ApiOperation(value = "还款方式查询", notes = "还款方式查询")
    @PostMapping(value = "/matchingAmortMethod")
    public TxnRespResult<MatchingAmortMethodRes> matchingAmortMethod (@Valid @RequestBody MatchingAmortMethodReq matchingAmortMethodReq) throws Exception {
        TxnRespResult<MatchingAmortMethodRes> result = new TxnRespResult<>();
        result.getSuccess(loanRelationInfoHandler.matchingAmortMethodHandle(matchingAmortMethodReq));
        return result;
    }
}
